<?php
ob_start();
session_start();
	include ("../BusinessLogicTier/DanhMucSPBUS.php");
	include ("../BusinessLogicTier/SanPhamBUS.php");
	require_once '../DataAccessTier/DBConnection.php'; 
	include ("../BusinessLogicTier/TinRaoVatBUS.php");
	include ("../BusinessLogicTier/VungBUS.php");
	include ("../BusinessLogicTier/TinhBUS.php"); 
	include ("../BusinessLogicTier/LoaiTinRaoVatBUS.php"); 
	
header('Content-Type: text/html; charset=UTF-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/sanphamraotin.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>rao vặt</title>
<!-- InstanceEndEditable -->
<link rel="stylesheet" type="text/css" href="css/timkiem.css"/>
<link rel="stylesheet" type="text/css" href="css/top.css"/>
<link rel="stylesheet" type="text/css" href="css/header.css"/>
<link rel="stylesheet" type="text/css" href="css/menutab.css"/>
<link rel="stylesheet" type="text/css" href="css/navigation.css"/>
<link rel="stylesheet" type="text/css" href="css/leftcontent.css"/>
<link rel="stylesheet" type="text/css" href="css/centercontent.css"/>
<link rel="stylesheet" type="text/css" href="css/rightcontent.css"/>
<link rel="stylesheet" type="text/css" href="css/footer.css"/>
<link rel="stylesheet" type="text/css" href="css/sanpham.css"/>
<link rel="stylesheet" type="text/css" href="css/contact.css"/> 
<link rel="stylesheet" type="text/css" href="css/dangtin.css"/>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>

<body>
 	
 	 
  
 	<div class="main">
 		<!--Top: Start-->   
    	<div class="top">
    		<?php include("top/top.php") ?>             
               
        </div>
        <!--Top: end-->
        <!-- header: start -->
        <div class="header">
        	<?php include("top/header.php") ?>
        </div>
        	
        <!--header:end-->
        <div class="clr"></div><!--*xóa đi phần float left, float right*/--> 
        <!--content:start-->
        
        <div class="content">
        	<!--menu tap -->
        	<div id="menu_tap">
           	  	<?php include("content/menu.php") ?>
          		 
            </div>
          	<!--navigation-->
            <div class="navigation"><span class="current"></span></div>
            <!--tim kiem -->
             <div class="timkiem_nv"> <?php include("content/timkiem.php") ?>
             </div>
             <!--left content-->
             <div class="left_content">
            
              	  <?php include("content/left.php") ?>
            </div>
            <!--center content-->
            <div class="center_content">
            <!-- InstanceBeginEditable name="EditRegion3" --> 
            	 <div class="center_title_bar">Đăng Tin Sản Phẩm</div>
                 <?php 
				 	$dangtintheo = 0;//0 là theo tỉnh, 1 là theo vùng, 2 là nhiều tỉnh
				 	$idMND = "1";
	
					$tinhBUS =  new TinhBUS();
					$vungBUS = new VungBUS();
					$sanphamBUS= new SanPhamBUS();
					$dmspBUS = new DanhMucSPBUS();
					$loaiTRVBUS = new LoaiTinRaoVatBUS();
					$trvBUS = new TinRaoVatBUS();
					 
					$dmsp = $dmspBUS->getDanhMucSP();
					$loaiTRV = $loaiTRVBUS->getLoaiTinRaoVat();
					
					$vung = $vungBUS->getVung();
					$dstinh = $tinhBUS->getTinh();//lấy danh sách tất cả các tỉnh
					
					
				?>
                 <form method="post" action="" name="dangtinraovat">
                <div class="dangtin">
                    <div class="title_dangtin">Nội Dung Tin:
                        <span class="title_dangtinghichu">(Bạn phải điền đầy đủ thông tin)</span>
                    </div>
                    <div class="chuyenmuc_dangtin">
                        <div class="title_chuyenmuc">Chuyên Mục:</div>
                        <div class="noidung_chuyenmuc">
                            <div class="select_chuyenmuc">
                                <select sel_id="" id="category_group" name="chuyenmucTRV" class="">
                                     
                                            <option value="0">Tất cả danh mục </option>
                		<?php foreach($dmsp as $objdmsp){?>					
                    
                        <option disabled="disabled" value="<?php echo $objdmsp->getMaDMSP();?>" style="text-align:center;background-color:#dcdcc3; font-weight: bold;">-- <?php echo $objdmsp->getTenDMSP();?> --</option>
                        <?php $sp = $sanphamBUS->getSanPhamByMaDMSP($objdmsp->getMaDMSP());
						if($sp!=NULL){
							foreach($sp as $objsp){?>	 
                    
                        	<option value="<?php echo $objsp->getMaSP();?>"><?php echo $objsp->getTenSP();?> </option>		                           
                    <?php }}}?> 
                                          
                                  </select>
                              </div>
                        </div>
                        <div class="clear"></div>
                    </div>
                     <div class="chuyenmuc_dangtin">
                        <div class="title_chuyenmuc">Vùng:</div>
                        <div class="noidung_chuyenmuc">
                            <div class="select_chuyenmuc">
                                     
                                        <select sel_id="" id="category_group1" name="vungTRV" class="">
                                           <option value="0">Tất cả các vùng </option>
                        <?php foreach($vung as $objvung){?>	
                        				
                    
                        <option value="<?php echo $objvung->getMaVung();?>" style="background-color:#dcdcc3; font-weight: bold;">-- <?php echo $objvung->getTenVung();?> --</option>
                        <?php $tinh = $tinhBUS->getTinhByMaVung($objvung->getMaVung());
						if($tinh!=NULL){
							
							foreach($tinh as $objtinh){?>	 
                    
                        	<option value="<?php echo $objtinh->getMaTinh();?>">  <?php echo $objtinh->getTenTinh();?> </option>		
                           
                    <?php }}}?>  
                                          </select>              
                                                                          
                                    <div class="hinhanhrss"> 
                                         <a href=""><img src="image/themtinh.png" width="20px" height="20px" /></a>
                                          <div class="nhieutinh_chuyenmuc">
                                          <?php foreach($dstinh as $objdstinh){?>
                                                <input name="nhieutinh" type="checkbox" value="<?php echo $objdstinh->getMaTinh();?> " class="checktinh" /><?php echo $objdstinh->getTenTinh();?><br/><?php }?>
                                                 
                                          </div>
                                	 <div> 
                             </div>
                              
                        </div>
                        <div class="clear"></div>
                    </div>
               </div>
               <div class="dangtin1">
                     
                    <div class="chuyenmuc_dangtin">
                        <div class="title_chuyenmuc">Bạn Đăng Tin:</div>
                        <div class="noidung_chuyenmuc">
                            <div class="radio_chuyenmuc">
                            <? foreach($loaiTRV as $objloaiTRV){?>
                                <div class="radio_chuyenmucchon">                                
                                    <input type="radio" value="<?php echo $objloaiTRV->getMaLoaiTRV();?>" name="loaiTRV" id="p_ad">
                                    <label for="p_ad"><?php echo $objloaiTRV->getTenLoaiTRV();?></label>&nbsp;
                                </div>
                                <?php }?>
                                 
                            
                            </div>
                        </div>
                        <div class="clear"></div>
                        
                    </div>
                     <div class="chuyenmuc_dangtin">
                            <div class="title_chuyenmuc">Tiêu Đề:</div>
                            <div class="noidung_chuyenmuc">
                                 <input type="text" placeholder="Dùng tiếng việt có dấu." title="Dùng tiếng việt có dấu." value="" maxlength="50" size="46" name="tieudeTRV" id="subject" class="input_long">
                            </div>
                            <div class="clear"></div>
                        
                    </div>
                     <div class="chuyenmuc_dangtin">
                            <div class="title_chuyenmuc">Nội Dung:</div>
                            <div class="noidung_chuyenmuc">
                                 <textarea placeholder="Điền nội dung tin chi tiết bạn muốn rao bằng tiếng việt có dấu." title="Điền nội dung tin chi tiết bạn muốn rao bằng tiếng việt có dấu." id="body" class="vietuni placeholder input_long_textarea" maxlength="2000" name="noidungTRV" rows="10" cols="43"></textarea> 
                            </div>
                            <div class="clear"></div>
                        
                    </div>
                      <div class="chuyenmuc_dangtin">
                            <div class="title_chuyenmuc">Giá:</div>
                            <div class="noidung_chuyenmuc">
                                 <input type="text" id="price" value="" maxlength="19" size="46" class="input_short" name="giaTRV">
                                <div class="fleft">&nbsp;VNĐ</div>
                            </div>
                            <div class="clear"></div>
                        
                     </div>
                     <div class="chuyenmuc_dangtin">
                            <div class="title_chuyenmuc">Hình:</div>
                            <div style="640px" class="noidung_chuyenmuc">
                                  <div class="khung_chuyenmuc">
                                        <div class="title_khungchuyenmuc">
                                        “Trăm nghe không bằng mắt thấy”. Tin có hình được xem nhiều gấp 7 lần.<br /> 
                ĐĂNG HÌNH ĐỂ BÁN CHẠY HƠN!</div>
                                  </div>
                                  
                                   <?php for($i=0;$i<6;$i++){?>
                                  <div>                                 
                                  <input type="file" title="chọn hình ảnh của bạn" value="hình ảnh" name="image_khunghinh" />
                                  <br /><br />
                                  </div>
                                  <?php }?>
                                  
                            </div>
                            <div class="clear"></div>
                                
                    </div>
                    <br /><br /><br /><br /><br />
                     <div class="chuyenmuc_dangtin">
                            <div class="title_chuyenmuc">&nbsp;</div>
                            <div class="noidung_chuyenmuc">
                                 <input type="submit" onclick="" value="Đăng Tin" name="submit_dangtin" class="submit_chuyenmuc">	
                                        
                                 <span style="margin-top:0px;" class="warning" id="minimum_images2"></span>
                                 
                            </div>
                            <div class="clear"></div>
                        
                     </div>  
                    
                
                </div>
                </form>
                 <?php 
							  $thoigian = date('Y-m-d H:i:s');
							 	
								 
									
								if(isset($_POST["submit_dangtin"]))
								{
									if(isset($_POST["noidungTRV"])==NULL||$_POST["giaTRV"]==NULL)
									{
										?>
										<script>
											alert("bạn chưa nhập nội dung ");
										</script>
										<?php
									}
									else
									{
										 	
											 $masanpham = $_POST["chuyenmucTRV"];
											 $mavung = 1;//$_POST["vungTRV"];
											 $loaitin = $_POST["loaiTRV"];
											 $gia = $_POST["giaTRV"];
											 $tieude = $_POST["tieudeTRV"];
											 $noidung = $_POST["noidungTRV"];
											 $nhieutinh = $_POST["nhieutinh"];
											 for($i=0;$i<count($nhieutinh);$i++)
											 {
												 //chèn cái gì thì chèn
											 }
											 $thoigian = date('Y-m-d H:i:s');
											 $hinhanh = "image/laptop.png";
											 
											 $trvObj = new TinRaoVat("", $loaitin, $tieude,$gia, $noidung, $hinhanh,
											 $thoigian,0, $idMND, $masanpham);
 											$trvBUS->insert($trvObj);?>
											 <script>
												alert("cám ơn bạn đã đăng tin ");								  						 
											</script>
											 
											 
								<?php }}?>
                	 
                    <!-- InstanceEndEditable -->
            </div>
             <!--right content-->
 	       <div class="right_content">               
                
           </div>
            
        </div>
        <!--Content end-->
        <div class="clr"></div><!--*xóa đi phần float left, float right*/--> 
        <!--footer-->
        <div class="footer">
        	<?php include("footer/footer.php") ?>
        </div>
        
    </div>
    
</body>
<!-- InstanceEnd --></html>
